package textapp.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import textapp.business.GroupMessageService;
import textapp.connector.MessageCode;
import textapp.connector.ServerConnectorMessage;

/**
 * Servlet implementation class DeleteGroupMessageJsonServlet
 */
public class DeleteGroupMessageJsonServlet extends GenericJsonServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DeleteGroupMessageJsonServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	@Override
	protected Object executeRequestJson(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		try {
			int gmId = Integer.parseInt(request.getParameter("gmid"));
			boolean result = new GroupMessageService().deleteGroupMessage(gmId);
			if (result) {
				return new ServerConnectorMessage(MessageCode.SUCCESS, "TRUE");
			} else {
				return new ServerConnectorMessage(MessageCode.SUCCESS, "FALSE");
			}
			
		}catch(NumberFormatException ex) {
			return new ServerConnectorMessage(MessageCode.FAIL);
		}
	}

    
	
}
